<link rel="stylesheet" href="/admin/assets/module/formSelects/formSelects-v4.css"/>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">编号：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="code" class="layui-input" type="text"
                                               placeholder="请输入入库计划单编号"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">入库类型：</label>
                                    <div class="layui-input-inline mr0">
                                        <select id="inoutTypeCode" name="inoutTypeCode"
                                                lay-filter="inoutTypeCode"></select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">状态：</label>
                                    <div class="layui-input-inline mr0">
                                        <select name="status" lay-filter="status">
                                            <option value="">选择状态</option>
                                            <option value="stockup">待入库</option>
                                            <option value="storage">入库完成</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" id="inventoryInoutSearch"
                                            lay-filter="formSubSearchLog" lay-submit>查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>
                            </div>
                            <div class="query-rt"></div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button type="button" id="inventoryInoutBtnAdd" class="layui-btn icon-btn color-reseda">
                                添加
                            </button>
                        </div>
                        <div class="lay-btn-rt">
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="inventoryInoutTable" lay-filter="inventoryInoutTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="inventoryInoutTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">详情</a>
    <a class="layui-btn layui-btn-xs" lay-event="print">打印条码</a>
    <!--{{# if(d.status =="stockup"){ }}
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="storageRecord">入库作业记录</a>
    {{# } }}-->


</script>
<script type="text/html" id="storageProductTableBar">
    {{# if(d.status =="unreceipted"){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="confirmSign">确定签收</a>
    {{# } }}
</script>

<script type="text/html" id="storageRecordTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="workDetail">查看详情</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="workPrint">打印</a>
</script>

<style>
    .inventoryInoutForm .layui-form-label{
        width: 100px;
    }
    .inventoryInoutForm .layui-input-block{
        margin-left: 140px;
    }
</style>

<!-- 表单详情弹窗 inventoryOutDetail-->
<script type="text/html" id="inventoryInoutForm">
    <form class="layui-form inventoryInoutForm model-form" action="" lay-filter="inventoryInoutForm">
        <input type="hidden" name="id" autocomplete="off" class="layui-input">
        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">入库类型</label>
                <div class="layui-input-block">
                    <select name="inoutTypeCode" lay-filter="inoutTypeCode" required lay-verify="required"
                            placeholder="请选择入库类型">
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">生产计划编号</label>
                <div class="layui-input-block">
                    <input type="text" name="productionPlanCode" placeholder="请输入生产计划编号" autocomplete="off"
                           class="layui-input">
                </div>
                <span></span>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>物料生产部门</label>
                <div class="layui-input-block" style="line-height: 36px">
                    <span style="color: red" id="bumen1">制造部/开刃工序</span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>生产台机工位</label>
                <div class="layui-input-block">
                    <select name="productionMachineId" required lay-verify="required" id="productionMachineId"
                            placeholder="请选择台机工位" lay-search>
                        <option value="">选择台机工位</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>生产负责人</label>
                <div class="layui-input-block">
                    <input type="text" name="manufactureHeadName" placeholder="请输入生成负责人" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>


        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>物料名称</label>
                <div class="layui-input-block">
                    <select name="skuCode" required lay-verify="required" id="skuCodeOption"
                            placeholder="请选择物料名称" lay-search>
                        <option value="">选择物料名称</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label">送料数量</label>
                <div class="layui-input-block">
                    <input type="text" name="feedQuantity" id="feedQuantitySum" placeholder="请输入送料数量"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>入库单位</label>
                <div class="layui-input-block">
                    <select name="unitId" required lay-verify="required" id="unitIdOption"
                            placeholder="请选择入库单位"
                            lay-search>
                        <option value="">选择包装单位</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>入库包装方案</label>
                <div class="layui-input-block">
                    <select name="pageSchemeId" lay-filter="pageSchemeId" required lay-verify="required"
                            id="pageSchemeIdOption" placeholder="请选择包装方案" lay-search>
                        <option value="">选择包装方案</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>生成包装SN码</label>
                <div class="layui-input-block" style="line-height: 36px;">
                    <span style="color: red" id="snNum"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>入库送料人</label>
                <div class="layui-input-block">
                    <input type="text" name="feedingPeople" placeholder="请输入送料人" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label"><span
                        style="color: red">*</span>入库仓库</label>
                <div class="layui-input-block">
                    <select name="warehouseId" required lay-verify="required" id="warehouseIdOption"
                            placeholder="请选择入库仓库">
                        <option value="">选择入库仓库</option>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-col-xs12">
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="remark" placeholder="备注" autocomplete="off" style="height: 80px;"
                              class="layui-input"/>
                </div>
            </div>
        </div>

        <div class="layui-form-item text-right">
            <div class="layui-input-block">
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                <button class="layui-btn" lay-submit lay-filter="inventoryInoutFormSubmit">提交</button>
            </div>
        </div>
    </form>
</script>
<!-- 表单详情弹窗 -->
<script type="text/html" id="inventoryOutDetail">
    <form lay-filter="inventoryOutDetailForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-col-xs6">
            <div id="codeSpan" class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库类型</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="storageTypeDesc"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span
                        style="color: red">*</span>生产计划编号</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="productionPlanCode"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span
                        style="color: red">*</span>物料生产部门</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red">制造部/开刃工序</span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span
                        style="color: red">*</span>生产台机工位</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="productionMachineSpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span
                        style="color: red">*</span>生产负责人</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="manufactureHeadNameSpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>物料名称</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="skuCodeSpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>送料数量</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="feedQuantitySpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库单位</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="storageUnitNameSpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span
                        style="color: red">*</span>入库包装方案</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="pageSchemeSpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span
                        style="color: red">*</span>生成包装SN码</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="snNumSpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span
                        style="color: red">*</span>入库送料人</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="feedingPeopleSpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span style="color: red">*</span>入库仓库</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="warehouseNameSpan"></span>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6">
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 100px;"><span
                        style="color: red">*</span>备注</label>
                <div class="layui-form-mid layui-word-aux">
                    <span style="color: red" id="remarkSpan"></span>
                </div>
            </div>
        </div>
    </form>
</script>


<!-- 打印条码 -->
<script type="text/html" id="packLabelTableForm">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <table class="layui-table" id="packLabelTable" lay-filter="packLabelTable"></table>
            </div>
        </div>
    </div>
</script>
<script type="text/html" id="packLabelTableBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="labelPrint">打印</a>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate', 'layedit'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var layedit = layui.layedit;
        var laydate = layui.laydate;
        var planId = "";//入库计划id
        var type = 0; //0是添加 1是查看详情
        var pageSnList = [];
        var storageTypeDesc = "";
        var productPackLabeList = [];
        var packLabelIdList = [];
        var amount = 0;//总签收数
        var skuCode = "";//用于接收出库计划物料的skuCode 在物料包装码数据点击签收时校验是否是出库计划的物料
        var inoutTypeName = "";//入库类型名称
        //查询仓库
        admin.req('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll', {}, function (res) {
            if (res.code == 200) {
                if (res.data.length > 0) {
                    $.each(res.data, function (index, item) {
                        $("#inWarehouseNameSelect").append(new Option(item.name, item.id));
                    })
                    form.render('select');
                }
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'GET');
        // 渲染表格
        var insTb = table.render({
            elem: '#inventoryInoutTable',
            url: config.base + 'enterprisecab/order/admin/inventoryInout/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'}
                , {field: 'id', title: 'ID', width: 60, hide: true}
                , {field: 'code', align: 'center', title: '入库计划单编号', width: 180}
                , {field: 'inoutTypeName', align: 'center', title: '入库类型'}
                , {field: 'productNum', align: 'center', title: '入库数'}
                , {field: 'unitName', align: 'center', title: '入库包装单位'}
                , {field: 'packLabelNum', align: 'center', title: '入库包装数'}
                , {field: 'quantityTotal', align: 'center', title: '最小单位数'}
                , {field: 'statusDesc', align: 'center', title: '状态'}
                , {field: 'creatorName', align: 'center', title: '操作员'}
                , {field: 'createTime', align: 'center', title: '入库时间', width: 160}
                , {align: 'center', toolbar: '#inventoryInoutTableBar', title: '操作', width: 200}
            ]],
            id: 'testReload',
            done: function (res, curr, count) {
            }
        });
        form.render('select');
        // 工具条点击事件
        table.on('tool(inventoryInoutTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showInventoryOutDetailModel(data);
            } else if (obj.event === 'print') { // 打印
                showPrintModel(data);
            } else if (obj.event === 'storageRecord') {
                showStorageRecordModel(data);
            }
        });
        //监听排序
        table.on('sort(inventoryInoutTable)', function (obj) {
            table.reload('inventoryInoutTable', {
                initSort: obj,
                where: {
                    sort: obj.field,
                    order: obj.type
                }
            });
        });
        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({
                where: data.field, page: {curr: 1}
            })
            return false;
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#inventoryInoutBtnAdd').click(function () {
            showEditModel();
        });

        // option渲染
        function loadSelectHtml(data, tips, htmltarget, type) {

            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type == 1) {
                    html += `<option value='${data[i].productType}'>${data[i].name}</option>`;
                } else if (type == 2) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type == 3) {
                    html += `<option value='${data[i].id}'>${data[i].warehouseName}</option>`;
                } else if (type == 4) {
                    html += `<option value='${data[i].skuCode}'  skuCode='${data[i].skuCode}'>${data[i].skuName}</option>`;
                } else if (type == 5) {
                    html += `<option value='${data[i].skuCode}'>${data[i].skuName}</option>`;
                } else if (type == 6) {
                    html += `<option value='${data[i].code}'>${data[i].name}</option>`;

                }
            }
            $("form select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        //查询入库类型
        admin.initDataSelect('enterprisecab/warehouse/admin/warehouseInventoryType/list', {inventoryType: 'in',limit:9999,status:'enable'}, "inoutTypeCode", null, "入库类型", null, "code");

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                closeBtn: 1,
                area: '800px',
                offset: '150px',
                title: data ? '修改入库单' : '添加入库单',
                content: $('#inventoryInoutForm').html(),
                success: function () {
                    //查询入库类型
                    admin.req('enterprisecab/warehouse/admin/warehouseInventoryType/list', {inventoryType: 'in',limit:9999,status:'enable'}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                loadSelectHtml(res.data, "选择入库类型", "inoutTypeCode", 6);
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                    //监听入库类型
                    form.on('select(inoutTypeCode)', function (data) {
                        inoutTypeName = data.elem[data.elem.selectedIndex].text;
                        if (data.value == "cutter") {
                            //查询物料常用包的数据
                            admin.req('enterprisecab/productCab/admin/productDetail/getAll', {inoutType: 1}, function (res) {
                                if (res.code == 200) {
                                    if (res.data.length > 0) {
                                        loadSelectHtml(res.data, "选择物料名称", "skuCode", 5);
                                    }
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'GET');
                            //查询所有物料单位
                            admin.req('enterprisecab/cabProduct/admin/productUnit/getAll', {}, function (res) {
                                if (res.code == 200) {
                                    if (res.data.length > 0) {
                                        loadSelectHtml(res.data, "选择包装单位", "unitId", 2);
                                    }
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'GET');
                        } else if (data.value == "production") {
                            //查询所有云端制造的物料
                            admin.req('enterprisecab/productCab/admin/productDetail/getAll', {inoutType: 2}, function (res) {
                                if (res.code == 200) {
                                    if (res.data.length > 0) {
                                        loadSelectHtml(res.data, "选择物料名称", "skuCode", 5);
                                    }
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'GET');
                            //查询所有物料单位
                            admin.req('enterprise/product/admin/productUnit/getAll', {}, function (res) {
                                if (res.code == 200) {
                                    if (res.data.length > 0) {
                                        loadSelectHtml(res.data, "选择包装单位", "unitId", 2);
                                    }
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'GET');
                        }
                    });

                    //查询所有台机设备
                    admin.req('enterprise/device/admin/device/getAll', {}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                $.each(res.data, function (index, item) {
                                    $("#productionMachineId").append(new Option(item.deviceCode, item.id));
                                })
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');

                    //查询所有包装方案
                    admin.req('enterprise/product/admin/productPack/getAll', {}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                $.each(res.data, function (index, item) {
                                    $("#pageSchemeIdOption").append(new Option(item.name, item.id));
                                })
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                    var baseRate = null;
                    //监听送料数的input值变化
                    $("#feedQuantitySum").blur(function () {
                        if (baseRate != null) {
                            var feedQuantity = $("#feedQuantitySum").val();
                            let snNum = Math.ceil(feedQuantity / baseRate);
                            $("#snNum").html(snNum);
                        }
                    })
                    //监听包装方案选择
                    form.on('select(pageSchemeId)', function (data) {
                        admin.req('enterprise/product/admin/productPack/getProductPackById', {packId: data.value}, function (res) {
                            if (res.code == 200) {
                                //换算率
                                baseRate = res.data.baseRate;
                                var feedQuantity = $("#feedQuantitySum").val();
                                //返回大于或等于一个给定数的最小整数
                                let snNum = Math.ceil(feedQuantity / baseRate);
                                $("#snNum").html(snNum);
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'GET');
                    });
                    //查询仓库
                    admin.req('enterprisecab/warehouse/admin/warehouse/getWarehouseVOAll', {}, function (res) {
                        if (res.code == 200) {
                            if (res.data.length > 0) {
                                $.each(res.data, function (index, item) {
                                    $("#warehouseIdOption").append(new Option(item.name, item.id));
                                })
                                form.render('select');
                            }
                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                    var layeditIndex52 = layedit.build('storageLocation', {
                        uploadImage: {
                            url: config.upload_url + 'layuiUpload?access_token=' + config.getToken(),
                            type: 'post'
                        }
                    });

                    if (data) {
                        var option = $("form select[name='transportType']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.transportType == item.text) {
                                data.transportType = item.value;
                            }
                        });
                    }


                    if (data) {
                        var option = $("form select[name='status']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.status == item.text) {
                                data.status = item.value;
                            }
                        });
                    }

                    if (data) {
                        var option = $("form select[name='storageType']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.storageType == item.text) {
                                data.storageType = item.value;
                            }
                        });
                    }
                    if (data) {

                    }
                    // 表单提交事件
                    form.on('submit(inventoryInoutFormSubmit)', function (d) {
                        layer.load(2);
                        d.field.storageLocation = layedit.getContent(layeditIndex52);
                        let snNum = $("#snNum").html();
                        d.field.snNum = snNum;
                        d.field.inoutTypeName = inoutTypeName;
                        console.log(d.field);
                        admin.req(data ? 'enterprisecab/order/admin/inventoryInout/update' : 'enterprisecab/order/admin/inventoryInout/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                //table.reload('inventoryInoutTable');
                                insTb.reload({
                                    page: {curr: 1}
                                })
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
            form.render();
        }

        //打印条码弹窗
        function showPrintModel(data) {
            admin.open({
                type: 1,
                area: ['1400px', '800px'],
                offset: '65px',
                title: "打印入库条码",
                content: $('#packLabelTableForm').html(),
                success: function () {
                    var productTable = table.render({
                        elem: '#packLabelTable',
                        url: config.base + 'enterprise/product/admin/productPackLabel/getInventoryPackLabelPageList?planId=' + data.id,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {field: 'number', title: '序号', width: 60, type: 'numbers'}
                            , {field: 'code', sort: true, title: '包装条码', width: 150}
                            , {
                                field: 'planCode', title: '所属入库计划', width: 150, templet(d) {
                                    return data.code;
                                }
                            }
                            , {field: 'productName', sort: true, title: '物料名称', width: 120}
                            , {field: 'skuSpecValueNames', title: '物料规格', width: 120}
                            , {field: 'packName', sort: true, title: '包装规格', width: 120}
                            , {field: 'baseRate', title: '单位包装数'}
                            , {field: 'unitName', title: '最小单位'}
                            , {field: 'printCount', title: '打印次数'}
                            , {align: 'center', toolbar: '#packLabelTableBar', title: '操作', width: 120}
                        ]]
                    });
                    // 工具条点击事件
                    table.on('tool(packLabelTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'labelPrint') { //打印条码
                            getPrintBarcode(data);
                        }
                    });
                }
            });
        }

        // 请求条码接口
        function getPrintBarcode(data) {
            layer.load(2);
            admin.req('enterprise/product/admin/productPackLabel/getBarCode', {code: data.code}, function (res) {
                layer.closeAll('loading');
                if (res.code == 200) {
                    var newstr = '<div style="text-align: center;padding: 20px;width: 100%;box-sizing: border-box;"><img src="' + res.data + '" style="max-width: 100%;"/></div>'
                    printBarcode(newstr)
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'GET');
        }

        // 打印条码
        function printBarcode(data) {
            admin.open({
                type: 1,
                area: ['700px', '350px'],
                offset: '65px',
                title: "打印预览",
                content: data,
                btn: ['打印', '取消'],
                yes: function () {
                    let newWin = window.open("");//新打开一个空窗口
                    newWin.document.write(data);//将表格添加进新的窗口
                    newWin.document.close();//在IE浏览器中使用必须添加这一句
                    newWin.focus();//在IE浏览器中使用必须添加这一句
                    newWin.print();//打印
                    newWin.close();//关闭窗口
                },
                btn2: function () {
                    layer.closeAll();
                }

            })

        }

        //显示入库计划详情弹窗
        function showInventoryOutDetailModel(data) {
            admin.open({
                type: 1,
                area: ['750px', '500px'],
                offset: ['150px', '600px'],
                title: "查看入库任务详情",
                content: $('#inventoryOutDetail').html(),
                success: function () {
                    admin.req('enterprisecab/order/admin/inventoryInout/getInventoryInoutById', {id: data.id}, function (res) {
                        if (res.code == 200) {
                            $("#storageTypeDesc").html(res.data.inoutTypeName);
                            $("#productionPlanCode").html(res.data.productionPlanCode);
                            $("#productionMachineSpan").html(res.data.productionMachine);
                            $("#manufactureHeadNameSpan").html(res.data.manufactureHeadName);
                            $("#skuCodeSpan").html(res.data.skuCode);
                            $("#feedQuantitySpan").html(res.data.feedQuantity);
                            $("#storageUnitNameSpan").html(res.data.unitName);
                            $("#pageSchemeSpan").html(res.data.pageScheme);
                            $("#feedingPeopleSpan").html(res.data.feedingPeople);
                            $("#warehouseNameSpan").html(res.data.warehouseName);
                            $("#warehouseName").html(res.data.warehouseName);
                            $("#remarkSpan").html(res.data.remark);
                            admin.req('enterprise/product/admin/productPack/getProductPackById', {packId: res.data.pageSchemeId}, function (paRes) {
                                if (paRes.code == 200) {
                                    //换算率
                                    var baseRate = paRes.data.baseRate;
                                    var feedQuantity = res.data.feedQuantity;
                                    //返回大于或等于一个给定数的最小整数
                                    let snNum = Math.ceil(feedQuantity / baseRate);
                                    $("#snNumSpan").html(snNum);
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'GET');

                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'GET');
                }
            });
        }

        // 导出excel
        $('#inventoryInoutBtnExport').click(function () {
            var checkRows = table.checkStatus('inventoryInoutTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>